def
¶You can define more than one function in a script.
three_reds.py
¶snapshot
¶Bit has the ability to take a snapshot of the world using the snapshot
function.
snap_three_reds.py
¶You can use any phrase you want when making a snapshot.
The Jump
buttons take you to the previous or next snapshot.
cosmo.py
¶When naming a function or variable:
_
(next to the zero key + shift) to break up compound namesgo_green
instead of gogreen
or goGreen
go
instead of Go
or GO
go
is different from Go
!In blue_squares.py
, when will Bit paint a blue square?
blue_squares.py
¶%%file for_class/blue_squares.py
from byubit import Bit
def reds(bit):
bit.paint('red')
bit.move()
bit.paint('red')
bit.move()
def blues(bit):
bit.paint('blue')
bit.move()
bit.paint('blue')
bit.move()
def greens(bit):
bit.paint('green')
bit.move()
bit.paint('green')
bit.move()
@Bit.empty_world(5, 3)
def run(bit):
reds(bit)
greens(bit)
if __name__ == '__main__':
run(Bit.new_bit)
Overwriting for_class/blue_squares.py
Defining a function is not the same as calling a function.
The very first line after def
can have a string. When this is the case, we call that string a docstring because it documents the function: you use it to describe what the function is for and how to use it.
Strings that use single quotation characters (e.g. "
or '
) are only one line.
If you want to use multiple lines for your string, use triple quotes ("""
or '''
).
Given the following starting world:
Draw four blue smiles:
smiles.py
¶def